function generateChart(data, chartType, chartId) {
    var barModel = eval('(' + data + ')');

    var tickInterval = 0;
    if(chartType != 'pie') {
        tickInterval = Math.ceil(barModel.columnkeys.length/10);
    }


    //jQuery("#highchartChart1" + chartId);
    var hc = jQuery("*[id$=highchartChart" + chartId + "]");
    var hcid = hc.attr('id');
    //var myWidth = jQuery('#' + hcid).css('width').slice(0,-2);
    //var width = jQuery("#" + hcid).width();

    var options = null;
    if(chartType == 'area') {
    	options = {
    	        chart : {
    	            renderTo :hcid,
    	            type : 'area',
    	            borderWidth :0,
    	            borderColor :'#EEEEEE',
    	            zoomType:'xy',
    	            backgroundColor: '#FAFAFA'
    	        },
    	        title : {
    	            text :barModel.hctitle
    	        },
    	        xAxis : {
    	            categories :barModel.columnkeys,
    	            tickmarkPlacement: 'on',
    	            title: {
    	                enabled: false
    	            }
    	        },
    	        yAxis : {
    	            title : {
    	                text : ''
    	            }
    	        },
    	        tooltip : {
    	            pointFormat : '<span style="color:{series.color}">{series.name}</span>: <b>{point.y:,.0f}</b> ({point.percentage:.1f}%)<br/>',
    	            shared: true
    	        },
    	        plotOptions : {
    	             area: {
    	                 lineColor: '#ffffff',
    	                 lineWidth: 1,
    	                 marker: {
    	                     lineWidth: 1,
    	                     lineColor: '#ffffff'
    	                 }
    	             }
    	        		
    	        },
    	        series : []
    	    };
    } else if(chartType == 'area2') {
    	options = {
    	        chart : {
    	            renderTo :hcid,
    	            type : 'area',
    	            borderWidth :0,
    	            borderColor :'#EEEEEE',
    	            zoomType:'xy',
    	            backgroundColor: '#FAFAFA'
    	        },
    	        title : {
    	            text :barModel.hctitle
    	        },
    	        xAxis : {
    	            categories :barModel.columnkeys,
    	            tickmarkPlacement: 'on',
    	            title: {
    	                enabled: false
    	            }
    	        },
    	        yAxis : {
    	            title : {
    	                text : ''
    	            }
    	        },
    	        tooltip : {
    	            pointFormat : '<span style="color:{series.color}">{series.name}</span>: <b>{point.y:,.0f}</b><br/>',
    	            shared: true
    	        },
    	        plotOptions : {
    	             area: {
    	                 lineColor: '#ffffff',
    	                 lineWidth: 1,
    	                 marker: {
    	                     lineWidth: 1,
    	                     lineColor: '#ffffff'
    	                 }
    	             }
    	        		
    	        },
    	        series : []
    	    };
    } else if(chartType == 'xy') {
    	options = {
    	        chart : {
    	            renderTo :hcid,
    	            borderWidth :0,
    	            borderColor :'#EEEEEE',
    	            zoomType:'xy',
    	            backgroundColor: '#FAFAFA'
    	        },
    	        title : {
    	            text :barModel.hctitle
    	        },
    	        xAxis : {
    	            categories :barModel.columnkeys,
    	        },
    	        yAxis: [{ // Primary yAxis
    	            labels: {
    	                format: '{value}',
    	                style: {
    	                    color: '#89A54E'
    	                }
    	            },
    	            title: {
    	                text: '人均在线时长（m）',
    	                style: {
    	                    color: '#89A54E'
    	                }
    	            }
    	        }, { // Secondary yAxis
    	            title: {
    	                text: '人均登录次数',
    	                style: {
    	                    color: '#4572A7'
    	                }
    	            },
    	            labels: {
    	                format: '{value}',
    	                style: {
    	                    color: '#4572A7'
    	                }
    	            },
    	            opposite: true
    	        }],
    	        tooltip : {
    	            shared: true
    	        },
    	        legend: {
    	            layout: 'vertical',
    	            align: 'left',
    	            x: 120,
    	            verticalAlign: 'top',
    	            y: 100,
    	            floating: true,
    	            backgroundColor: '#FFFFFF'
    	        },
    	        series : [
    	                  
							{
							    name: '次数',
							    color: '#4572A7',
							    type: 'column',
							    yAxis: 1,
							    data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
							    tooltip: {
							        valueSuffix: ' mm'
							    }
							
							}, {
							    name: '分钟',
							    color: '#89A54E',
							    type: 'spline',
							    data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6],
							    tooltip: {
							        valueSuffix: '°C'
							    }
							}
    	                  
    	                  ]
    	    };
    } else if(chartType == 'pie') {
    	options = {
	    		        chart: {
	    		        	renderTo :hcid,
	    		            type: 'pie',
	    		            options3d: {
	    		                enabled: false,
	    		                alpha: 45,
	    		                beta: 0
	    		            }
	    		        },
	    		        title: {
	    		            text: barModel.hctitle
	    		        },
	    		        tooltip: {
	    		            pointFormat: '<b>{point.y:,.0f}</b> ({point.percentage:.1f}%)<br/>'
	    		        },
	    		        plotOptions: {
	    		            pie: {
	    		                allowPointSelect: true,
	    		                cursor: 'pointer',
	    		                depth: 35,
	    		                dataLabels: {
	    		                    enabled: true,
	    		                    format: '{point.name}'
	    		                }
	    		            }
	    		        },
	    		        series: []
    	    };
    } else if (chartType == 'bar') {
		options = {
			chart : {
				renderTo :hcid,
				type : 'bar'
			},
			title : {
				text : ''
			},
			subtitle : {
				text : ''
			},
			xAxis : [ {
				categories : barModel.columnkeys,
				reversed : false
			}, { // mirror axis on right side
				opposite : true,
				reversed : false,
				categories : barModel.columnkeys,
				linkedTo : 0
			} ],
			yAxis : {
				title : {
					text : null
				},
				labels : {
					formatter : function() {
						return (Math.round(Math.abs(this.value) * 10000)/100).toFixed(2) + '%';
					}
				},
				min : -barModel.maxData,
				max : barModel.maxData
			},

			plotOptions : {
				series : {
					stacking : 'normal'
				}
			},

			tooltip : {
				formatter : function() {
					return '<b>' + this.series.name + ' ' + this.point.category + '</b><br>' + '' + (Math.round(Math.abs(this.point.y) * 10000)/100).toFixed(2) + '%';
				}
			},

			series : []

		};
	}  else if (chartType == 'bar2') {
		options = {
				chart : {
					renderTo :hcid,
					type : 'bar'
				},
				title : {
					text : ''
				},
				subtitle : {
					text : ''
				},
				xAxis : {
					categories : barModel.columnkeys,
					title : {
						text: null
					}
				},
				yAxis : {
					min: 0,                                                        
		            title: {                                                       
		                text: '',                             
		                align: 'high'                                              
		            },                                                             
		            labels: {                                                      
		                overflow: 'justify'                                        
		            }
				},

				plotOptions: {                                                     
		            bar: {                                                         
		                dataLabels: {                                              
		                    enabled: true                                          
		                }                                                          
		            }                                                              
		        },     

				tooltip : {
					formatter : function() {
						return '<b>' + this.series.name + ' ' + this.point.category + '</b><br>' + '' + Math.round(this.point.y).toFixed(2);
					}
				},
				
				legend: {                                                          
		            layout: 'vertical',                                            
		            align: 'right',                                                
		            verticalAlign: 'top',                                          
		            x: -40,       
		            y: 100,                                                        
		            floating: true,                                                
		            borderWidth: 1,                                                
		            backgroundColor: '#FFFFFF',                                    
		            shadow: true                                                   
		        },                                                                 
		        credits: {                                                         
		            enabled: false                                                 
		        },

				series : []

			};
		} else if (chartType == 'columnadd') {
			options = {
			        chart: {
			        	renderTo :hcid,
			            type: 'column'
			        },
			        title: {
			            text: barModel.hctitle
			        },
			        xAxis: {
			            categories: barModel.columnkeys
			        },
			        yAxis: {
			            min: 0,
			            title: {
			                text: ''
			            },
			            stackLabels: {
			                enabled: true,
			                style: {
			                    fontWeight: 'bold',
			                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
			                }
			            }
			        },
			        
			        legend: {
			            backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
			        },
			        tooltip: {
				            formatter : function() {
				            	return '<b>' + this.x + '</b><br>' + this.series.name
				            			+ ': ' + this.y + '<br>' + 'DAU-总数: '
				            			+ this.point.stackTotal;
				            }
			        },
			        plotOptions: {
			            column: {
			                stacking: 'normal',
			                dataLabels: {
			                    enabled: true,
			                    color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
			                }
			            }
			        },
			        series: []
			};
		} else if (chartType == 'linemore') {
			options = {
	    	        chart : {
	    	            renderTo :hcid,
	    	            type :'spline',
	    	        },
	    	        title : {
	    	            text :barModel.hctitle
	    	        },
	    	        plotOptions : {
	    	        	spline: {
    	                    marker: {
    	                        enabled: false
    	                    }
	    	            },
	    	            line: {
    	                    marker: {
    	                        enabled: false
    	                    }
    	                }
	    	        },
	    	        tooltip : {
	    	        	formatter: function() {
	    	        		if (parseInt(barModel.percent)==1) {
	    	        			return '<span style="color:' + this.series.color +'">'+ this.x +'</span>:' + (Math.round(this.y * 10000)/100).toFixed(2) + '%';
	    	        		} else {
	    	        			return '<span style="color:' + this.series.color +'">' + this.x +'</span>:' + this.y;
							}
	                    	
		        		}
	    	        },
	    	        xAxis : {
	    	            categories :barModel.columnkeys,
	    	            labels: {
	    	                step: 12,
	    	                staggerLines: 1
	    	              }
	    	        },
	    	        yAxis : {
	    	            min :barModel.minData,
	    	            max :barModel.maxData,
	    	            allowDecimals :true,
	    	            title : {
	    	                text :barModel.yTitle
	    	            },
	    	        	labels: {
	                    formatter: function() {
		                    	if (parseInt(this.value)!=this.value) {
		                    		 return (Math.round(this.value * 10000)/100).toFixed(2) + '%';
								} else {
									return this.value;
								}
	                    	}
	    	        	}
	    	        },
	    	        series : []
	    	    };
		}  else if (chartType == 'columnline') {
		options = {
			chart : {
				renderTo :hcid
			},
			title : {
				text :getNowFormatDate() + '在线人数'
			},
			tooltip : {
				formatter: function() {
					if (this.series.type == 'spline') {
						return this.y;
					} else {
						return '<span style="color:' + this.series.color +'">' + this.x +'</span>:' + this.y;
					}
				}
			},
			xAxis : {
				categories :barModel.columnkeys,
				labels: {
					rotation: 90
				}
			},
			yAxis : {
				title : {
					text :''
				},
			},

			series : []
		};
	} else {
			options = {
    	        chart : {
    	            renderTo :hcid,
    	            defaultSeriesType :chartType,
    	            borderWidth :0,
    	            borderColor :'#EEEEEE',
    	            zoomType:'xy',
    	            backgroundColor: '#FAFAFA'
    	        },
    	        title : {
    	            text :barModel.hctitle
    	        },
    	        plotOptions : {
    	            column : {
    	                pointPadding :0.8,
    	                borderWidth :0
    	            }
    	        },
    	        tooltip : {
    	        	formatter: function() {
    	        		if (parseInt(barModel.percent)==1) {
    	        			return '<span style="color:' + this.series.color +'">'+ this.series.name +'</span>:' + this.x + '->' + (Math.round(this.y * 10000)/100).toFixed(2) + '%';
                        } else {
    	        			return '<span style="color:' + this.series.color +'">' + this.series.name +'</span>:' + this.x + '->' + this.y;
						}
                    	
	        		}
    	        },
    	        plotOptions: {
    	            column: {
    	                pointPadding: 0.1,
    	                borderWidth: 0
    	            }
    	        },
    	        xAxis : {
    	            categories :barModel.columnkeys,
    	            tickInterval : tickInterval
    	        },
    	        yAxis : {
    	            min :barModel.minData,
    	            max :barModel.maxData,
    	            allowDecimals :true,
    	            title : {
    	                text :barModel.yTitle
    	            },
    	        	labels: {
                    formatter: function() {
                        if (parseInt(barModel.percent)==1) {
                            return (Math.round(this.value * 10000)/100).toFixed(2) + '%';
                        } else {
                            return this.value;
                        }
	                    	/*if (parseInt(this.value)!=this.value) {
	                    		// return (Math.round(this.value * 10000)/100).toFixed(2) + '%';
                                return this.value;
							} else {
								return this.value;
							}*/
                    	}
    	        	}
    	        },
    	        series : []
    	    };
    }
    
    var dataArray = barModel.data;
    var dataName = barModel.names;
    
	for ( var i = 0; i < dataArray.length; i++) {
		if (chartType == 'pie') {
			 options.series.push( {data :dataArray[i]});
		} else if (chartType == 'xy') {
			
		} else if (chartType == 'bar') {
			if (i % 2 == 0) {
				var tmpArray = new Array([dataArray[i].length]);
				for (var k = 0; k < dataArray[i].length; k++) {
					tmpArray[k] = -dataArray[i][k];
				}
				
				options.series.push( {
		            name :dataName[i],
		            data :tmpArray});
			} else {
				options.series.push( {
		            name :dataName[i],
		            data :dataArray[i]});
			}
		} else if (chartType == 'columnline') {
			break;
		} else {
			for (var k = dataArray[i].length - 1; k >= 0; k--) {
				if (dataArray[i][k] == 0) {
					dataArray[i][k] = null;
				} else {
					break;
				}
			}
			
			 options.series.push( {
		            name :dataName[i],
		            data :dataArray[i]});
		}
    }

	if (chartType == 'columnline') {
		var baselength = dataArray.length;
		var tmpType = new Array([baselength + 2]);
		var tmpDataName = new Array([baselength + 2]);
		var tmpDataArray = new Array([baselength + 2]);
		for (var i = 0; i < baselength; i++) {
			tmpType[i] = 'column';
			tmpDataName[i] = dataName[i];
			tmpDataArray[i] = dataArray[i];
		}
		tmpType[baselength] = 'spline';
		tmpType[baselength + 1] = 'spline';
		tmpDataName[baselength] = '在线人数';
		tmpDataName[baselength + 1] = '在线人数';
		var a2500 = new Array([dataArray[0].length]);
		var a3000 = new Array([dataArray[0].length]);
		for (var i = 0; i < dataArray[0].length; i++) {
			a2500[i] = 2500;
			a3000[i] = 3000;
		}
		tmpDataArray[baselength] = a2500;
		tmpDataArray[baselength + 1] = a3000;

		for (var i = 0; i < tmpType.length; i++) {
			options.series.push({
				type :tmpType[i],
				name :tmpDataName[i],
				showInLegend: false,
				data :tmpDataArray[i],
				marker: {
					enabled: false
				}});
		}
	}

    chart = new Highcharts.Chart(options);
    
	var bb = arguments[3] ? arguments[3] : "";
	if (bb != "") {
		var ww = jQuery("#" + bb).width();
		var hh = jQuery("#" + hcid).height();
		
		chart.setSize(ww, hh);
	}
}

function spinnered() {
	var selected = jQuery("label[id$='radioHide']").text();
	if (selected == '0') {
		return true;
	} else {
		return false;
	}
}

function getNowFormatDate() {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	/*var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
		+ " " + date.getHours() + seperator2 + date.getMinutes()
		+ seperator2 + date.getSeconds();*/
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
	return currentdate;
}